package com.d5xx.hunters.commands;

import com.d5xx.hunters.API.Hunter;
import com.d5xx.hunters.API.HunterPlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@SuppressWarnings("NullableProblems")
public class Language implements TabExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String a, String[] args) {
        if (!(sender instanceof Player player)) return true;
        HunterPlayer hunterPlayer = Hunter.getHunterPlayer(player);
        if (args.length == 0) { //子命令长度为0
            hunterPlayer.sendKeyMessage("Language-help", false);
        } else if (args.length == 1) {
            switch (args[0]) {
                case "help":
                    hunterPlayer.sendKeyMessage("Language-help", false);
                    break;
                case "zh-cn":
                    hunterPlayer.setPlayerSetting("language", "zh-cn");
                    hunterPlayer.sendKeyMessage("Language-set", true);
                    break;
                default:
            }
        }
        return true;
    }

    @Override
    public List<String> onTabComplete(CommandSender sender, Command cmd, String a, String[] args) {
        //Tab补全
        if (args.length == 1) {
            List<String> result = new ArrayList<>(Arrays.asList("help", "zh-cn"));
            result.removeIf(s -> !s.startsWith(args[0].toLowerCase()));
            return result;
        }
        return null;
    }
}
